//
//  HMWelcomeViewController.swift
//  sina
//
//  Created by Kent on 16/9/26.
//  Copyright © 2016年 Ming. All rights reserved.
//

import UIKit
import SDWebImage

class HMWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        UISetup()
        
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        startAnimation()
    }
    
    func startAnimation() {
        
        UIView.animate(withDuration: 1.2, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: [], animations: {
            
                let h = CGFloat(UIScreen.main.bounds.height * 0.1) + 85
            
                self.circleIcon.snp.updateConstraints({ (make) in
                    make.top.equalTo(self.view).offset(h)
                })
            
                self.view.layoutIfNeeded()
            
            }) { (_) in
                
                UIView.animate(withDuration: 1, animations: {
                    
                    self.welcomeLabel.alpha = 1
                    
                    }, completion: { (_) in
                        
                        NotificationCenter.default.post(name: NSNotification.Name(KchangeRootViewController), object: nil)
                        
                })
                
        }
        
    }

    func UISetup() {
        
        view.backgroundColor = UIColor.white
        
        view.addSubview(circleIcon)
        
        circleIcon.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(UIScreen.main.bounds.height * 0.7)
            make.width.height.equalTo(85)
        }
    
        view.addSubview(welcomeLabel)
        
        welcomeLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(circleIcon.snp.bottom).offset(5)
        }
        
        circleIcon.sd_setImage(with: HMUserAccountViewModel.sharedAccountViewModel.iconUrl)
    
    }
    
    lazy var circleIcon: UIImageView = {
       
        let ci = UIImageView()
        ci.image = #imageLiteral(resourceName: "avatar_default")
        ci.cornerRadius = 42
        ci.layer.borderWidth = 1
        ci.layer.borderColor = UIColor.lightGray.cgColor
        
        return ci
    }()
    
    lazy var welcomeLabel: UILabel = {
       
        let l = UILabel(title: "Welcome Back", fontSize: 14, textColor: UIColor.darkGray)
        l.alpha = 0
        return l
    }()
    
}

















































